/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

//01导入

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * <p>Project: jse2306 - CalendarDemo</p>
 * <p>Powered by webrx On 2023-10-11 14:08:07</p>
 * <p>description: </p>
 *
 * @author 李四 [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class CalendarDemo {
    public static void main(String[] args) {
        //使用Calendar类实例，计算生活了多少天?
        //var birth = "1995-10-20";

        var y3 = 1985;
        var m3 = Calendar.OCTOBER;
        var d3 = 20;
        var c3 = Calendar.getInstance();
        c3.set(y3, m3, d3);
        System.out.printf("%tF %<tT %<tA %<tp %<tB%n", c3);

        long t3 = System.currentTimeMillis() - c3.getTimeInMillis();
        System.out.println(t3 / 1000 / 60 / 60 / 24);
        System.out.println(t3 / (1000 * 60 * 60 * 24));

        System.exit(0);


        //02实例化
        Calendar cc = Calendar.getInstance();

        //1
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss EEEE aaa MMMMM");
        SimpleDateFormat sf = new SimpleDateFormat("MM月dd日 HH:mm");
        System.out.println(sdf.format(cc.getTime()));
        System.out.println(sf.format(cc.getTime()));

        //2
        System.out.printf("%tF %<tT %<tA %<tp %<tB%n", cc);

        //add 新增
        //cc.add(Calendar.DATE, 5);
        //System.out.println("------------------当前日期，5天后的日期：");
        //System.out.printf("%tF %<tT %<tA %<tp %<tB%n", cc);

        //cc.add(Calendar.DATE, -21); //21天前
        //System.out.printf("%tF %<tT %<tA %<tp %<tB%n", cc);
        //cc.add(Calendar.WEEK_OF_MONTH, -3); //3周前
        //System.out.printf("%tF %<tT %<tA %<tp %<tB%n", cc);

        //cc.add(10, 100);
        //cc.add(Calendar.HOUR, 100);
        //System.out.printf("%tF %<tT %<tA %<tp %<tB%n", cc);

        //set 设置  1985-10-15 18:20:30 设置指定的日期
        //cc.set(1985, Calendar.OCTOBER, 15, 18, 20, 30);
        //System.out.printf("%tF %<tT %<tA %<tp %<tB%n", cc);

        //get 获取
        int yyyy = cc.get(Calendar.YEAR);
        int mm = cc.get(Calendar.MONTH) + 1;
        int dd = cc.get(Calendar.DATE);

        //1 星期日 2星期一 4星期三
        int day = cc.get(Calendar.DAY_OF_WEEK);
        System.out.println(day);

        //Date 和 Calendar对象相互转换  CST UTC

        //Calendar -> Date
        Date m1 = cc.getTime();
        Date m2 = new Date(cc.getTimeInMillis());


        //Date -> Calendar
        Calendar cc2 = Calendar.getInstance();
        cc2.setTime(m1);


        System.exit(0);
        //2 java.util.Calendar
        //02 获取Calendar类的实例，实例化
        var c = Calendar.getInstance();  //获取实例化对象相当于new Calendar()

        System.out.printf("%tF %<tT %<tA %<tp %<tB%n", c);
        Date d31 = c.getTime();//此方法是将日历工具类实例，转换为java.util.Date对象

        //转换为时间戳
        long tt1 = d31.getTime();
        long tt2 = c.getTimeInMillis();

        //1 java.util.Date
        var d = new Date();
        long d1 = d.getTime(); //将日期类对象，转换为时间戳(long数字整数)
        System.out.printf("%tF %<tT %<tA %<tp %<tB%n", d);

        //时间戳
        long t = System.currentTimeMillis();
        System.out.printf("%tF %<tT %<tA %<tp %<tB%n", t);


        //System.out.println(TimeZone.getTimeZone(ZoneId.of("GMT+8")));
        //TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("GMT+0")));
        Locale.setDefault(Locale.UK);
        //格式化时间戳
        System.out.printf("%tF %<tT %<tA %<tp %<tB%n", 0L);


    }
}
